﻿using System;
using System.Collections.Generic;
using System.Text;
using ProtocolVN.Framework.Core;

namespace ProtocolVN.Framework.Win
{
    public class HelpString
    {
        public static string NganCachHangNgan(decimal value)
        {
            string Kq = "";
            bool ExistTP = false;
            decimal temp = Math.Abs(value);
            String[] M = null;
            if (value.ToString().Contains("."))
            {
                M = value.ToString().Split('.');
                ExistTP = true;
                temp = Math.Abs(HelpNumber.DecimalToInt64(M[0]));
            }

            if (temp < 1000)
                return value.ToString();
            else
            {
                while (temp > 1000)
                {
                    long PhanNguyen = (long)temp / 1000;
                    long PhanDu = (long)temp % 1000;
                    Kq = PhanDu.ToString() + Kq;
                    Kq = "." + Kq;
                    temp = PhanNguyen;
                }
                Kq = temp.ToString() + Kq;
                if (value < 0)
                    Kq = "-" + Kq;
                if (ExistTP)
                    Kq = Kq + "," + M[1];
            }
            return Kq;
        }
    }
}
